package com.hengxinguotong.hxgtwygsp.ui.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.WindowManager;
import android.widget.TextView;

import com.hengxinguotong.baselibrary.smarttab.SmartTabLayout;
import com.hengxinguotong.hxgtwygsp.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * TODO
 *
 * @author hjz
 * @version V1.0.0
 * @since 2019/3/26 19:54
 */

public abstract class DialogActivity extends BaseDialogActivity
{
    @BindView(R.id.dialog_title)
    public TextView dialogTitle;
    @BindView(R.id.smart_tab)
    SmartTabLayout smartTab;
    @BindView(R.id.mViewPager)
    ViewPager mViewPager;

    protected List<BaseTabFragment> baseTabFragmentList;
    protected FragmentAdapter fragmentAdapter;

    @OnClick(R.id.dialog_close)
    public void onViewClicked()
    {
        finish();
    }

    @Override
    public int getLayoutResId()
    {
        return R.layout.activity_dialog;
    }

    @Override
    public void init()
    {
        baseTabFragmentList = new ArrayList<>();
        initFragmentList();
        mViewPager.setOffscreenPageLimit(4);
        fragmentAdapter = new FragmentAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(fragmentAdapter);
        smartTab.setViewPager(mViewPager);
        int position = getIntent().getIntExtra("position", 0);
        mViewPager.setCurrentItem(position);
    }

    public abstract void initFragmentList();

    public class FragmentAdapter extends FragmentPagerAdapter
    {

        public FragmentAdapter(FragmentManager fm)
        {
            super(fm);
        }

        @Override
        public Fragment getItem(int position)
        {
            return baseTabFragmentList.get(position);
        }

        @Override
        public int getCount()
        {
            return baseTabFragmentList.size();
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position)
        {
            return baseTabFragmentList.get(position).getTabText();
        }
    }
}
